package com.uton.mvp_demo.view;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.uton.mvp_demo.R;
import com.uton.mvp_demo.presenter.MainActivityPresenter;

public class MainActivity extends AppCompatActivity
        implements IBaseViewController<MainActivityPresenter> {

    private MainActivityPresenter presenter;
    private ProgressDialog progressDialog;
    private TextView textViewShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);

        presenter=new MainActivityPresenter();
        presenter.attach(this);

        textViewShow=findViewById(R.id.tv_show);
        findViewById(R.id.btn_show).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.showWeather();
            }
        });

    }


    @Override
    public MainActivityPresenter showLoading() {
        progressDialog.show();
        return presenter;
    }

    @Override
    public void dismissLoading() {
        progressDialog.dismiss();
    }

    @Override
    public MainActivityPresenter showPaintedEggshell(String msg) {
        textViewShow.setText(msg);
        return presenter;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.detach();
    }
}
